package com.chinacoal.hr.levelapi.util;

import io.swagger.annotations.ApiModelProperty;

/**
 * @author: YunTao.Li
 * @create: 2019-12-12 17:09
 * @description:
 **/
public class Result<T> {
    @ApiModelProperty("状态码,10000为成功")
    private int code;

    @ApiModelProperty("提示信息")
    private String msg;

    @ApiModelProperty("数据")
    private T data;

    public Result()
    {
        success(null);
    }

    private Result(T data) {
        this.code = 10000;
        this.msg = "success";
        this.data = data;
    }

    public Result(CodeMsg msg) {
        if (null == msg) {
            return;
        }
        this.code = msg.getCode();
        this.msg = msg.getMsg();
    }

    public Result(CodeMsg msg, T data) {
        if (null == msg) {
            return;
        }
        this.code = msg.getCode();
        this.msg = msg.getMsg();
        this.data = data;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public static <T> Result<T> success(T data)
    {
        return new Result(data);
    }
    public static <T> Result<T> success() {
        return new Result(CodeMsg.Success);
    }

    public static <T> Result<T> error(CodeMsg msg)
    {
        return new Result(msg);
    }

    public static <T> Result<T> IError(CodeMsg msg, T data)
    {
        return new Result(msg, data);
    }
}
